<?php

namespace app\common\model;

/**
 * [NewsTopic  资讯评论表]
 * @author [C。]
 * @return html
 */
class NewsTopic extends Base
{
    protected $name = 'news_topic';

    /**
     * 根据搜索条件获取列表信息
     */
    public function getlist($map, $from = 0, $size = 5,$field = 't.id,am.id memid,am.img,am.username,am.introduction,t.addr,t.content,t.imgs,t.addtime,am.identity,t.parid',$parid = 1)
    {
        $order = ['t.id' => 'desc'];
        if($parid == 1){
            $join = [
                ['app_member am', 'am.id = t.comment_uid'],
            ];
        }else{
            $join = [
                ['app_member am', 'am.id = t.memid'],
            ];
        }

        $result = $this->field($field)
            ->alias('t')
            ->join($join)
            ->where($map)
            ->order($order)
            ->limit($from, $size)
            ->select();

        return $result;
    }

    /**
     * 根据搜索条件获取总条数
     */
    public function getCount($map,$parid = 1)
    {
        if($parid == 1){
            $join = [
                ['app_member am', 'am.id = t.comment_uid'],
            ];
        }else{
            $join = [
                ['app_member am', 'am.id = t.memid'],
            ];
        }
        $result = $this->alias('t')
            ->join($join)
            ->where($map)
            ->count();

        return $result;
    }

    /**
     * [findData  根据id获取信息]
     * @author [C。]
     * @param string $id
     * @return array
     */
    public function findOne($id = '',$idname = 'id')
    {
        $order = ['id' => 'desc'];
        if(empty($id))
            exception('传递数据不合法');

        return  $this->where($idname, $id)->order($order)->find();
    }
    /**
     * 根据搜索条件获取列表信息
     */
    public function getAlllist($map)
    {
        $order = ['t.id' => 'desc'];
        $join = [
            ['app_member am', 'am.id = t.comment_uid'],
        ];
        $result = $this->field('am.id memid,am.img,am.username,am.introduction,t.content,t.imgs,t.create_time,t.id,am.identity,t.parid')
            ->alias('t')
            ->join($join)
            ->where($map)
            ->order($order)
            ->select();

        return $result;
    }
    /**
     * 根据搜索条件获取列表信息
     */
    public function getlists($map,$map1, $from = 0, $size = 5,$field)
    {
        $order = ['t.id' => 'desc'];

        $join = [
            ['app_member am', 'am.id = t.comment_uid'],
        ];


        $result = $this->field($field)
            ->alias('t')
            ->join($join)
            ->where($map)
            ->whereOr($map1)
            ->order($order)
            ->limit($from, $size)
            ->select();

        return $result;
    }

    /**
     * 根据搜索条件获取总条数
     */
    public function getCounts($map,$map1)
    {
        $join = [
            ['app_member am', 'am.id = t.comment_uid'],
        ];
        $result = $this->alias('t')
            ->join($join)
            ->where($map)
            ->whereOr($map1)
            ->count();

        return $result;
    }
    /**
     * 根据搜索条件获取列表信息
     */
    public function getAll($map,$from = 0, $size = 5,$field='*')
    {
        $order = ['id' => 'desc'];

        $result = $this->field($field)
            ->where($map)
            ->order($order)
            ->limit($from, $size)
            ->select();

        return $result;
    }
    /**
     * 根据搜索条件获取总条数
     */
    public function getAllcount($map)
    {
        $result = $this->where($map)->count();

        return $result;
    }
}
